local skel = fk.CreateSkill{
  name = "kqf__fuqing",
}

local KleeU = require "packages/klee_xy_I/utility/k_utility"

Fk:loadTranslationTable{
  ["kqf__fuqing"] = "福倾",
  [":kqf__fuqing"] = "你可以将一张黑色基本牌作为【闪电】使用并摸两张牌；"..
  "当你受到黑色锦囊牌造成的伤害时，当前回合角色可以将此牌当【兵粮寸断】置入你的判定区并防止此伤害。",
  ["#kqf__fuqing"] = "福倾：你可以将一张黑色基本牌作为【闪电】使用并摸两张牌",
  ["#kqf__fuqing2"] = "福倾：你可以将被使用的伤害牌当【兵粮寸断】置入 %src 的判定区并防止其受到的伤害",

  ["$kqf__fuqing1"] = "祸根未绝，转而滋蔓。",
  ["$kqf__fuqing2"] = "无德之亲，终为祸根。",
}

skel:addEffect("active", {
  prompt = "#kqf__fuqing",
  card_num = 1,
  target_num = 0,
  can_use = function(self, player)
    return not player:hasDelayedTrick("lightning") and not table.contains(player.sealedSlots, Player.JudgeSlot)
  end,
  target_filter = Util.FalseFunc,
  card_filter = function(self, player, to_select, selected)
    if #selected == 0 and Fk:getCardById(to_select).color == Card.Black and Fk:getCardById(to_select).type == Card.TypeBasic then
      local card = Fk:cloneCard("lightning")
      card:addSubcard(to_select)
      return not player:prohibitUse(card) and not player:isProhibited(player, card)
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    room:useVirtualCard("lightning", effect.cards, player, player, skel.name)
    room:drawCards(player,2)
  end,
})

skel:addEffect(fk.DamageInflicted, {
  can_refresh = function(self, event, target, player, data)
    local card = Fk:cloneCard("supply_shortage")
    return target == player and player:hasSkill(skel.name) and
    --     玩家受伤              玩家有技能
      data.card and data.card.type == Card.TypeTrick and data.card.color == Card.Black and #data.card.subcards <= 1 and player.room:getCardArea(data.card) == Card.Processing and
    --有实体牌       锦囊牌                               黑色牌                             非多张转化牌                  没被奸雄拿走
      not player:hasDelayedTrick("supply_shortage") and not table.contains(player.sealedSlots, Player.JudgeSlot)--and not player.room.current:isProhibited(player, card)
    --可以被兵粮寸断
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local turnplayer = room.current
    local cho = KleeU.askYesOrNo(turnplayer, "#kqf__fuqing2:" .. player.id, skel.name)
    if cho then
      local card = Fk:cloneCard("supply_shortage")
      card.skillName = skel.name
      if #data.card.subcards < 1 then
        card:addSubcard(data.card.id)
      else
        card:addSubcards(data.card.subcards)
      end
      player:addVirtualEquip(card)
      room:moveCardTo(card,Player.Judge,player,fk.ReasonJustMove,skel.name)
      player.room:notifySkillInvoked(player, skel.name)
      player:broadcastSkillInvoke(skel.name)
      data:preventDamage()
    end
  end,
})


return skel